﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using DAO;
using DTO;
using System.Windows.Forms;

namespace BaiTap1
{
    enum Status { view, insert, update, delete };
    public partial class frm_QLNhanVien : Form
    {
        NhanVien_DTO _nhan_vien;
        Status TrangThai = Status.view;
        public frm_QLNhanVien()
        {
            InitializeComponent();
            LoadData();
        }
        public void EnableButton()
        {
            BT_XOA.Enabled = true;
            BT_THEM.Enabled = true;
            BT_SUA.Enabled = true;

            BT_CAPNHAT.Enabled = false;
            BT_HUY.Enabled = false;
        }
        public void DisableButton()
        {
            BT_XOA.Enabled = false;
            BT_THEM.Enabled = false;
            BT_SUA.Enabled = false;

            BT_CAPNHAT.Enabled = true;
            BT_HUY.Enabled = true;
        }
        public void LoadData()
        {
            NhanVien_DTO_bindingSource.DataSource = NhanVien_DAO.SelectAll();
        }
        private void BT_HUY_Click(object sender, EventArgs e)
        {

        }

        private void BT_CAPNHAT_Click(object sender, EventArgs e)
        {

        }

        private void BT_SUA_Click(object sender, EventArgs e)
        {

        }

        private void BT_XOA_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void frm_QLNhanVien_Load(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void BT_THEM_Click(object sender, EventArgs e)
        {
            DisableButton();
            TrangThai = Status.insert;
            _nhan_vien = NhanVien_DTO_bindingSource.AddNew() as NhanVien_DTO;
        }

        private void BT_XOA_Click_1(object sender, EventArgs e)
        {

        }

        private void BT_SUA_Click_1(object sender, EventArgs e)
        {
            DisableButton();
            TrangThai = Status.update;
        }

        private void BT_CAPNHAT_Click_1(object sender, EventArgs e)
        {
            EnableButton();
            if (TrangThai == Status.insert)
            {
                string result = NhanVien_DAO.Insert(_nhan_vien);

                if (result == "true")
                {
                    NhanVien_DTO_bindingSource.DataSource = NhanVien_DAO.SelectAll();
                    _nhan_vien = null;
                }
                else
                {
                    MessageBox.Show(result, "Thông tin");
                }
            }
            else if (TrangThai == Status.update)
            {
                string result = "";//NhanVien_DAO..PhanQuyen(nguoiDung);

                if (result == "true")
                {
                    NhanVien_DTO_bindingSource.DataSource = NguoiDung_DAO.SelectAll();
                    _nhan_vien = null;
                }
                else
                {
                    MessageBox.Show(result, "Thông tin");
                }
            }
            TrangThai = Status.view;
        }

        private void BT_HUY_Click_1(object sender, EventArgs e)
        {
            EnableButton();
            TrangThai = Status.view;
        }
    }
}
